<%-- 
    Document   : HomePage
    Created on : 19-05-2011, 21:26:25
    Author     : ngloc_it
--%>

<%@page import="uit.jee.lib.utilities.SystemProperities"%>
<%@page import="uit.jee.lib.dto.BookDTO"%>
<%@page import="java.util.ArrayList"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">


<%
    int numBook = 0;
    String bookTypeId = "TT";
    ArrayList<BookDTO> books = (ArrayList<BookDTO>) session.getAttribute("books");
    if((books != null) && (!books.isEmpty())){
        numBook = books.size();
        bookTypeId = books.get(0).getBookTypeId();
    }

    int currentPage = Integer.parseInt(session.getAttribute("page").toString());
%>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script language="javascript" type="text/javascript" src="../js/javascriptfile.js"></script>
        <link rel="stylesheet" type="text/css" href="../css/style.css">

        <%--<script language="javascript" type="text/javascript" src="../js/Common.js"></script>--%>
        <title>Trang chủ</title>
    </head>
    <body>
        <div id="wrapper">
            <input type="hidden" id="hbooktypeid" name="hbooktypeid" value="<%=bookTypeId%>"/>
            <input type="hidden" id="hpage" name="hpage" value="<%=currentPage%>"/>

            <%@include file ="./subpage/menu.jsp" %>
            <%@include file ="./subpage/header.jsp" %>
            <div class="divider"></div>
            <%@include file ="./subpage/searchbar.jsp" %>

            <div id="orangerow">

                <%@include file="./subpage/navOrange.jsp" %>

                <div class="col">
                    <div id="bookmonth">
                        <div id="bookmonth_imaged"></div>
                        <div id="bookmonth_title">
                            <%
                                String bookType = "";
                                if(numBook > 0)
                                    bookType = books.get(0).getBookType();
                            %>
                            <p style="font-size: 14px; color: #FF0014;"><%=bookType%></p>
                        </div>
                        <div id="bookmonth_author">            
                            
                            <table width="473" border="1" id="tableinfo">
                                <%
                                if(numBook > 0) {
                                    for (int i = 0; i < numBook; i++){
                                %>
                                <tr>
                                    <td width="40"><img src="../<%=books.get(i).getImgPath()%>"/></td>
                                    <td width="85"><a href="../BookDetail?bookid=<%=book.get()%>"><%=books.get(i).getName()%></a></td>
                                    <td width="74"><%=books.get(i).getAuthor()%></td>
                                    <td width="79"><%=books.get(i).getPublisher()%></td>

                                    <%
                                    int status = books.get(i).getStatus();
                                    String strStatus = SystemProperities.getBookStatusString(status);
                                    %>
                                    <td width="64"><%=strStatus%></td>
                                </tr>
                                <%}%> <!--End for-->
                                <%}%> <!--End if-->
                            </table>
                            <p>&nbsp;</p>

                        </div>
                        <div style="float:right;">
                            <input name="back" type="button" value=" Lùi Lại" onclick="reloadprebook()">
                            <input name="next" type="button" value="Tiếp theo" onclick="reloadnextbook()">
                        </div>

                    </div>

                    <!-- end bookmonth -->       
                </div><!-- end .col -->
                <div id="whitey"></div>
                <div class="clear">
                    <div class="fix">               
                    </div>             
                </div>
            </div><!-- end orangerow -->

            <div id="greenrow">
                <%@include file="./subpage/navGreen.jsp" %>                          
                <div class="clear"></div>
            </div><!-- end greenrow -->

            <%@include file="./subpage/footer.jsp" %>     
        </div><!-- end wrapper -->
    </body>

    <script  type = "text/javascript" >
        function createRequestObject(){
            var req;
            if(window.XMLHttpRequest){
                req = new XMLHttpRequest();
            }else if(window.ActiveXObject){
                req = new ActiveXObject("Microsoft.XMLHTTP");
            }else{
                alert('Your browser is not IE 5 or higher, or Firefox or Safari or Opera');
            }
            return req;
        }

        //Make the XMLHttpRequest Object
        var http = createRequestObject();
        function reloadnextbook(){
            var page = document.getElementById("hpage").value + 1;

            var booktypeid = document.getElementById("hbooktypeid").value;

            alert("next");
            if(http){
                //BookSameType?booktypeid=TT&function=load&page=0
                http.open("GET","../BookSameType?booktypeid="+ booktypeid +"&function=reload&page="+page,true);
                http.onreadystatechange = handleResponse;
                http.send(null);
            }
        }

        function reloadprebook(){
            var page = document.getElementById("hpage").value;
            var booktypeid = document.getElementById("hbooktypeid").value;

            if(page > 0)
                page--;
            alert("pre");
            if(http){
                //BookSameType?booktypeid=TT&function=load&page=0
                http.open("GET","../BookSameType?booktypeid="+ booktypeid +"&function=reload&page="+page,true);
                http.onreadystatechange = handleResponse;
                http.send(null);
            }
        }

        function handleResponse(){
            if(http.readyState == 4 && http.status == 200){
                var detail=document.getElementById("tableinfo");
                detail.innerHTML=http.responseText;
            }
        }
    </script>
</html>
